home *** CD-ROM | disk | FTP | other *** search
Wrap
var PersonasRotatorSetInterval = { STRINGS:null, getlibraryfileURI : function () { var file = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties) .get("ProfD", Components.interfaces.nsIFile); file.append("personasrotator"); file.append("library.rdf"); var ios = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var URL = ios.newFileURI(file); return URL.spec; }, populateItems : function () { var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotatorSetInterval.getlibraryfileURI()); var container=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:library")); var genericpersonasseqenumurator=container.GetElements(); var namePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#name"); while (genericpersonasseqenumurator.hasMoreElements()) { var collection=genericpersonasseqenumurator.getNext(); var nametarget=ds.GetTarget(collection,namePredicate,true); if (nametarget) { var name = nametarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value; } var newmenuitem=document.createElement("menuitem"); newmenuitem.setAttribute("label",name); newmenuitem.setAttribute("id",name+"menuitem"); newmenuitem.setAttribute("class","collection-menuitem"); document.getElementById("collistpopup").appendChild(newmenuitem); } }, cancelDialog : function () { return true; }, acceptDialog : function () { var choseninterval=document.getElementById("setintervaltimelist").value; var retrievedSeconds=PersonasRotatorSetInterval.retrieveIntervalSeconds(choseninterval); var chosencategory=document.getElementById("rotationcategorylist").value; var retrievedCategory=chosencategory; var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); personasrotatorprefsinstance.setIntPref("extensions.personasrotator.rotationinterval",retrievedSeconds); personasrotatorprefsinstance.setCharPref("extensions.personasrotator.rotationcategory",retrievedCategory); //if saved then rotation should begin personasrotatorprefsinstance.setBoolPref("extensions.personasrotator.rotationenabled",true); //updateRotationInterval is true method. Do not change it. window.opener.PersonasRotator.updateRotationInterval(retrievedSeconds); return true; }, retrieveIntervalSeconds:function(passedInterval){ if(passedInterval=="0") return 60; else if(passedInterval=="1") return 120; else if(passedInterval=="2") return 300; else if(passedInterval=="3") return 600; else if(passedInterval=="4") return 900; else if(passedInterval=="5") return 1200; else if(passedInterval=="6") return 1800; else if(passedInterval=="7") return 3600; else if(passedInterval=="8") return parseInt(document.getElementById("customtime").getAttribute("customtime")); }, retrieveIntervalNumber:function(currentInterval){ if(currentInterval==60) return 0; else if(currentInterval==120) return 1; else if(currentInterval==300) return 2; else if(currentInterval==600) return 3; else if(currentInterval==900) return 4; else if(currentInterval==1200) return 5; else if(currentInterval==1800) return 6; else if(currentInterval==3600) return 7; else return 8; }, retrieveCategoryName:function(currentCategory){ if(currentCategory=="All") return 0; else if(currentCategory=="My Favorites") return 1; else if(currentCategory=="Abstract") return 2; else if(currentCategory=="Causes") return 3; else if(currentCategory=="Fashion") return 4; else if(currentCategory=="Film and TV") return 5; else if(currentCategory=="Firefox") return 6; else if(currentCategory=="Foxkeh") return 7; else if(currentCategory=="Holiday") return 8; else if(currentCategory=="Music") return 9; else if(currentCategory=="Nature") return 10; else if(currentCategory=="Other") return 11; else if(currentCategory=="Scenery") return 12; else if(currentCategory=="Solid") return 13; else if(currentCategory=="Sports") return 14; else if(currentCategory=="Websites") return 15; else return 0; //for most popular and news bugs }, handleWindowLoad :function(event){ PersonasRotatorSetInterval.STRINGS = document.getElementById("setintervalBundle"); document.getElementById("savesetintervalbutton").addEventListener("command",PersonasRotatorSetInterval.handleSetIntervalButtonCommand,false); document.getElementById("cancelsetintervalbutton").addEventListener("command",PersonasRotatorSetInterval.cancelSetIntervalButtonCommand,false); var personasrotatorprefsinstance = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); var personasrotatorrotationinterval = personasrotatorprefsinstance.getIntPref("extensions.personasrotator.rotationinterval"); var personasrotatorrotationcategory = personasrotatorprefsinstance.getCharPref("extensions.personasrotator.rotationcategory"); document.getElementById('intervalsecondstext').firstChild.nodeValue='Interval is '+personasrotatorrotationinterval+' seconds'; document.getElementById("setintervaltimelist").selectedIndex=PersonasRotatorSetInterval.retrieveIntervalNumber(personasrotatorrotationinterval); document.getElementById("rotationcategorylist").selectedIndex=PersonasRotatorSetInterval.retrieveCategoryName(personasrotatorrotationcategory); //selindex is needed for custom revertback document.getElementById("setintervaltimelist").setAttribute("selindex",document.getElementById("setintervaltimelist").selectedIndex); document.getElementById("rotationcategorylist").setAttribute("catselindex",document.getElementById("rotationcategorylist").selectedIndex); //when custom value is saved with no change document.getElementById('customtime').setAttribute('customtime',personasrotatorrotationinterval); }, handleSetIntervalButtonCommand:function(event){ if(PersonasRotatorSetInterval.acceptDialog()) window.close(); }, cancelSetIntervalButtonCommand:function(event){ window.close(); }, onCategoryChange:function(event){ if(event.currentTarget.value=='My Favorites') { if (!(window.opener.PersonaService.favorites && window.opener.PersonaService.favorites.length > 0 &&window.opener.PersonaService.isUserSignedIn)) { //revert back. confirm is lagging revertion back. so it is put before confirm event.currentTarget.selectedIndex=event.currentTarget.getAttribute("catselindex"); if(confirm("Rotation of My Favorites requires logging in the system. Would you like to log in now?")) window.opener.gBrowser.selectedTab=window.opener.gBrowser.addTab("http://www.getpersonas.com/signin?return=/gallery/All/Favorites"); } } else { event.currentTarget.setAttribute("catselindex",event.currentTarget.selectedIndex); } }, onIntervalChange:function(event){ if(event.currentTarget.value!='8') { document.getElementById('intervalsecondstext').firstChild.nodeValue='Interval is '+PersonasRotatorSetInterval.retrieveIntervalSeconds(event.currentTarget.selectedItem.getAttribute('value'))+" seconds"; event.currentTarget.setAttribute("selindex",event.currentTarget.selectedIndex); } else { var promptwarning=PersonasRotatorSetInterval.STRINGS.getString("setInSeconds"); var customInterval=""; function validate(passedcustomInterval) { customInterval=passedcustomInterval; if (customInterval==null) return null; customInterval=customInterval.replace(/^\s+|\s+$/g,''); while (customInterval=="") { customInterval=PersonasRotatorSetInterval.createPromptPrompt(PersonasRotatorSetInterval.STRINGS.getString("emptyWarning")); if (customInterval==null) return null; customInterval=customInterval.replace(/^\s+|\s+$/g,''); } while (!isNaN(customInterval)&& parseInt(customInterval) < 60) { customInterval=PersonasRotatorSetInterval.createPromptPrompt(PersonasRotatorSetInterval.STRINGS.getString("lessThan60")); if (customInterval==null) return null; customInterval=customInterval.replace(/^\s+|\s+$/g,''); while (customInterval=="") { customInterval=PersonasRotatorSetInterval.createPromptPrompt(PersonasRotatorSetInterval.STRINGS.getString("setInSeconds")); if (customInterval==null) return null; customInterval=customInterval.replace(/^\s+|\s+$/g,''); } } return customInterval; } function checkTextualCollision(passedcustomInterval){ if (passedcustomInterval==null) return false; if(isNaN(passedcustomInterval)) return true; return false; } while(checkTextualCollision(validate(PersonasRotatorSetInterval.createPromptPrompt(promptwarning)))){ promptwarning=PersonasRotatorSetInterval.STRINGS.getString("setInNumber"); }; if (customInterval==null) { //revertback event.currentTarget.selectedIndex=event.currentTarget.getAttribute("selindex"); return; } document.getElementById('intervalsecondstext').firstChild.nodeValue='Interval is '+customInterval+' seconds'; document.getElementById('customtime').setAttribute('customtime',customInterval); event.currentTarget.setAttribute("selindex",event.currentTarget.selectedIndex); } }, createPromptPrompt:function(promptString){ var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); var input = {value:""}; var check = {value:false}; var result= prompt.prompt(null,"Personas Rotator",promptString,input,null,check); if(result==false) return null; else return input.value; } } window.addEventListener("load",PersonasRotatorSetInterval.handleWindowLoad,false);